package com.sloth.bear.controller;

import com.sloth.bear.dto.request.TodoListRequest;
import com.sloth.bear.dto.request.TodoRequest;
import com.sloth.bear.dto.vo.TodoVo;
import com.sloth.bear.service.TodoService;
import lombok.RequiredArgsConstructor;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 待办事项控制器
 */
@RestController
@RequestMapping("/todo")
@RequiredArgsConstructor
public class TodoController {

    private final TodoService todoService;

    /**
     * 创建待办事项
     */
    @PostMapping("/create")
    public TodoVo createTodo(@RequestBody @Valid TodoRequest request) {
        return todoService.createTodo(request);
    }

    /**
     * 待办事项列表
     */
    @GetMapping("/list")
    public List<TodoVo> listTodo(TodoListRequest request) {
        return todoService.listTodo(request);
    }

    /**
     * 获取待办事项详情
     */
    @GetMapping("/{id}")
    public TodoVo detailsTodo(@PathVariable Long id) {
        return todoService.detailsTodo(id);
    }

    /**
     * 更新待办事项
     */
    @PutMapping("/{id}")
    public TodoVo updateTodo(@PathVariable Long id, @RequestBody TodoRequest request) {
        return todoService.updateTodo(id, request);
    }

    /**
     * 删除待办事项
     */
    @DeleteMapping("/{id}")
    public Boolean deleteTodo(@PathVariable Long id) {
        return todoService.deleteTodo(id);
    }
}